<template>
	<view class="container-gray">
		<view v-if="dataList.length >0">
			<view style="display: flex;justify-content: flex-end;background: #FFFFFF;padding: 10upx 20upx;margin-bottom: 1px;">
				<view class="icon-clear" @click="clear">x</view>
			</view>
			<view @click="goDetail(item.id)" v-for="(item,index) in dataList" :key="index" class="flex-box" style="background: #FFFFFF;padding: 20upx;margin-bottom: 1px;">
				<image :src="item.imgUrl" mode="aspectFill" style="width: 320upx;height: 160upx;border-radius: 10upx;" />
				<view style="flex: 1;margin-left: 20upx;">
					<view style="height: 120upx;">{{item.title}}</view>
					<!-- <view style="color: #666666;font-size:16upx;">{{item.classHour}}课时</view> -->
					<view style="font-size: 20upx;color: #6A6A6A;" v-if="item.status == 0">未开始</view>
					<view style="font-size: 20upx;color: #6A6A6A;" v-if="item.status == 1">未完成</view>
					<view style="font-size: 20upx;color: #6A6A6A;" v-if="item.status == 2">已完成</view>
				</view>
			</view>
		</view>
		<view class="top-search-box" v-else>
			<view>热门搜索</view>
			<view class="key-words-box">
				<view class="key-words" v-for="(item,index) in keyList" :key="index"></view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		post_md5
	} from '../../common/request'
	export default {
		data() {
			return {
				keyList: [],
				page: 1,
				dataList: [],
				title: ''
			}
		},
		onNavigationBarSearchInputChanged(e) {
			console.log(e)
			this.title = e.text
			console.log(this.title)
		},
		onNavigationBarSearchInputConfirmed(e) {
			console.log(e)
			this.search()
		},
		onNavigationBarButtonTap: function() {
			this.search()
		},
		methods: {
			search() {
				post_md5('/train-app/courseapp/getcourselist', {
					page: this.page,
					title: this.title,
					orderType: 1,
					userId: uni.getStorageSync('userId')
				}).then(res => {
					console.log(res)
					if (res.code == 200) {
						this.dataList = res.data.list
					} else {
						this.dataList = []
					}
				})
			},
			clear() {
				// this.title = ''
				this.dataList = []
			},

			goDetail(id) {
				uni.navigateTo({
					url: '/pages/course/detail?id=' + id
				})
			}
		}
	}
</script>

<style>
	.top-search-box {
		padding: 30upx;
		font-size: 28upx;
		margin-top: 1px;
		background: #ffffff;
		color: #999999;
	}

	.key-words-box {
		display: flex;
		/* justify-content: space-between; */
		flex-wrap: wrap;
	}

	.key-words {
		background: #f7f7f7;
		border: 1px solid #d5d2d2;
		border-radius: 36upx;
		padding: 4upx 30upx;
		color: #666666;
		margin-top: 30upx;
		margin-right: 24upx;
	}

	.icon-clear {
		width: 30upx;
		height: 30upx;
		border: 1px solid #999999;
		border-radius: 50%;
		color: #999999;
		text-align: center;
		line-height: 30upx;
	}
</style>
